package fangbing.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import fangbing.dao.UserDao;
import fangbing.model.User;
import fangbing.util.page.Page;
import fangbing.util.page.PageBean;

@Service("userService")
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;

	/*
	 * 新增用户
	 */
	public void addUser(User user) {
		userDao.addUser(user);
	}

	/*
	 * 通过ID查询用户表
	 */
	public Map<String, Object> searchUserById(User user) {
		Map<String, Object> map = new HashMap<String, Object>();
		User user1 = userDao.searchUserById(user);
		map.put("user", user1);
		return map;
	}

	/*
	 * 查询用户列表分页
	 */
	public Map<String, Object> searchUserListByPage(PageBean<User> poPageBean,
			User user) {

		Map<String, Object> map = new HashMap<String, Object>();

		map.put("user", user);

		poPageBean.setParams(map);

		List<User> userList = userDao.searchUserListByPage(poPageBean);

		Page<User> page = new Page<User>(userList, poPageBean);

		map.put("page", page);

		return map;
	}
	
	/**
	 * 修改用户信息
	 * */
	public void updateUser(User user) {
		
		userDao.updateUser(user);
	}
	
	/**
	 * 删除用户信息
	 * */
	public void deleteUser(User user) {
		
		userDao.deleteUser(user);
		
	}
	
	/*
	 * 通过userName查询用户表记录
	 */
	public Map<String, Object> searchUserByUserName(User user) {
		Map<String, Object> map = new HashMap<String, Object>();
		User userInfo = userDao.searchUserByUserName(user);
		map.put("user", userInfo);
		return map;
	}

	

	

}
